/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bice.util;

import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 *
 * @author sirius
 */
public class FacesUtil {
    
    private static final String LANG = "lang";
    
    public static Object getSpringBean(ServletContext servletContext, String name) {
        WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        return context.getBean(name);
    }
    
    public static Object getELValue(String bean, String property) {
        FacesContext context = FacesContext.getCurrentInstance();
        return context.getApplication().evaluateExpressionGet(context, String.format("#{%s.%s}", bean, property), Object.class);
    }

    public static String getLang(String property) {
        return (String)getELValue(LANG, property);
    }
    
}